home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 038a / bas_int1.zip / FILEXIST.BAS < prev    next >
BASIC Source File  |  1991-02-17  |  5KB  |  106 lines

  1. '==========================================================================
  2. '                    DOS Interrupt File Exist Routine
  3. '                      Written for QuickBASIC 4.5
  4. '                     Randy Sharpe  CIS 72425,1247
  5. '                          December 12, 1989
  6. '****************************************************************************
  7. '            Sample Main Program calling SUB DoesFileExist
  8. '***************************************************************************
  9. '
  10. '      You may eliminate this block by instead adding the metacommand:
  11. '      "$include qb.bi in your code, but it contains some extra goodies
  12. '      you probably won't need.
  13. '      If running within QuickBASIC environment, you must load quickbasic
  14. '      using "/l qb.qlb"; this will load the "quick library" version of
  15. '      qb.lib. When producing an exe file from OUTSIDE of QuickBASIC using
  16. '      bc and link, be sure to "link-in" QB.LIB. Typically, this is
  17. '      accomplished by typing the following on the LIBRARIES line when
  18. '      prompted by LINK:
  19. '
  20. '              BCOM45 + QB (+ any other libs you may have)
  21. '      This will link in the necessary object code for CALL INTERRUPT.
  22. '      If producing an EXE from within QuickBASIC environment, all will
  23. '      be handled automatically.
  24.  
  25. TYPE RegType
  26.      ax    AS INTEGER    'AH/AL regs
  27.      bx    AS INTEGER    'BH/BL regs
  28.      cx    AS INTEGER    'CH/CL regs
  29.      dx    AS INTEGER    'DH/DL regs
  30.      bp    AS INTEGER    'base pointer
  31.      si    AS INTEGER    'source index reg
  32.      di    AS INTEGER    'destination index reg
  33.      Flags AS INTEGER    'flags reg
  34. END TYPE
  35.  
  36. DIM SHARED InRegs AS RegType, OutRegs AS RegType, True, False
  37.  
  38. DECLARE SUB DoesFileExist (FileExists!, FileName$)
  39. DECLARE SUB INTERRUPT (IntNumber AS INTEGER, _
  40.                        InRegs AS RegType, _
  41.                        OutRegs AS RegType)
  42.  
  43. '-------------------------------------------------------------------------
  44. CLS
  45. INPUT "Please Enter File Name To Search For: ", FileName$
  46.  
  47. CALL DoesFileExist(FileExists!, FileName$)
  48.  
  49. IF FileExists! THEN
  50.    'CALL ReadFile(FileName$)              'call the file read routine
  51.    PRINT FileName$; " Found"              'test purposes
  52. ELSE
  53.    'CALL FileNotFoundErrMsg(FileName$)    'call the error message routine
  54.    PRINT FileName$; " Not Found"          'test purposes
  55. END IF
  56.  
  57.  
  58.  
  59. '==========================================================================
  60. '                    DOS Interrupt File Exist Routine
  61. '                      Written for QuickBASIC 4.5
  62. '                     Randy Sharpe  CIS 72425,1247
  63. '                          December 12, 1989
  64. '============================================================================
  65. '  Subroutine: DoesFileExist (FileExists!, FileName$)
  66. '
  67. '  Input    : File name to search for in FileName$. This filename may contain
  68. '             drive/path info, but will default to current if absent. It may
  69. '             also contain wildcard and pattern match chars "*" and "?".
  70. '  Process  : Does a DOS INT21, service 4E to find the first occurence (if
  71. '             any) of file string contained in FileName$ in designated path &
  72. '             dir (if you need to find all occurences, you must continue
  73. '             all ensuing searches with INT21H, service 4FH). For a read, we
  74. '             want it to exist, but for a write, we want to give a message if
  75. '             it does exist to make sure user wants to overwrite it. For
  76. '             technical reference for this interrupt, see Microsoft Basic
  77. '             Language Reference.
  78. '  Output   : Exist Boolean in FileExists
  79. '  Coupling : Called by Main
  80. '             Calls DOS Interrupt 21, service 4E
  81. '
  82. '  Declare as follows:
  83. '                 DECLARE SUB DoesFileExist (FileExists!, FileName$)
  84. '                 DECLARE SUB INTERRUPT (IntNumber AS INTEGER, _
  85. '                                        InRegs AS RegType, _
  86. '                                        OutRegs AS RegType)
  87. '============================================================================
  88. SUB DoesFileExist (FileExists!, FileName$)
  89.  
  90.  
  91.    IntFileName$ = FileName$ + CHR$(0)
  92.  
  93.    InRegs.ax = &H4E00
  94.    InRegs.dx = SADD(IntFileName$)
  95.    InRegs.cx = &H0
  96.    CALL INTERRUPT(&H21, InRegs, OutRegs)
  97.  
  98.    CarryFlag& = (OutRegs.Flags AND &H1)
  99.  
  100.    FileExists! = CarryFlag& - 1         'File exists if FileExists! = -1
  101.                                         'File does not exist if it = 0
  102.  
  103. END SUB
  104.  
  105. 
  106.